<?php

include("../../utility/connection.php");
include("../../model/mSupplier.php");
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $vIDSupplier = trim(mysql_real_escape_string($_POST["hidUpdateID"]));
    $vTxtUpdate = trim(mysql_real_escape_string($_POST["hidUpdate"]));
    //echo 'id barang: '.$vIDInformasi.', update: '.$vTxtUpdate;
    
    if ($vTxtUpdate == '') {
        // tampilkan pada form
        $getDetilSupplier = fnSupplierById($vIDSupplier);
        $count = mysql_num_rows($getDetilSupplier);
        if ($count == 1) {
            $_SESSION['ubah'] = '1';
            $_SESSION['idBarang'] = $vIDSupplier;
            $detilSupplier = mysql_fetch_array($getDetilSupplier);
            $_SESSION['detilBarang'] = $detilSupplier;
        }
        
    } else if ($vTxtUpdate == '1') {
        //echo "update data pada database";
        unset($_SESSION['ubah']);
        unset($_SESSION['idBarang']);
        unset($_SESSION['detilBarang']);
        
        $Nama = trim(mysql_real_escape_string($_POST["Editbox1"]));
        $Alamat = trim(mysql_real_escape_string($_POST["Editbox2"]));
        $Telp = trim(mysql_real_escape_string($_POST["Editbox3"]));
        $Email = trim(mysql_real_escape_string($_POST["Editbox4"]));
        
        fnUpdateSupplier($vIDSupplier,$Nama,$Alamat,$Telp,$Email);
    }

    header("location: ../mstSupplier.php");
}
?>
